{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">添加字段</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段类型</label>
                            <div class="layui-input-inline">
                                <select id="type" name="type" lay-filter="type" class="required" lay-verify="required">
                                <option value='' >请选择字段类型</option>
                                    {volist name="type" id="vo"}
                                        <option value="{$vo.name}" >{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">字段名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="field" lay-verify="required" placeholder="必填：字段名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">别名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name"  lay-verify="required" placeholder="必填：别名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        
                        <div class="layui-col-lg12" id="field_setup">

                        </div>                        
                        <!--
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段设置</label>
                            <div class="layui-input-block">
                                <div class="layui-col-lg12" id="field_setup">
        
                                </div>  
                            </div>
                        </div>
                        -->
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证规则</label>
                            <div class="layui-input-inline">
                                <select name="pattern" lay-verify="required">
                                    {volist name="pattern" id="vo"}
                                    <option value="{$vo.name}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">class名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="class" lay-verify="required" placeholder="请输入class名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">是否必填</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="required"  value="1" title="是">
                                    <input type="radio" name="required" checked value="0" title="否">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">字符长度</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="minlength" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="maxlength" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">错误信息</label>
                                <div class="layui-input-block">
                                    <input type="text" name="errormsg" value="" placeholder="验证失败错误信息" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="moduleid" value="{:input('mid')}">
                                <button class="layui-btn" lay-submit lay-filter="add-but">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form'],function(){
         var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element,form = layui.form,mid = $('#mid').val();
        form.on('select(type)', function(type){
            field_setting(type);
        });
		
		//添加提交
		form.on('submit(add-but)', function(data){
			admin.req({
				url: '{:url(SYS_PATH."/field/add")}'
				, type: 'post'
				, data: data.field
				,success: function (res) {
					if(res.code==0){
									window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000000']}, function () {
										layer.closeAll("iframe");
										//刷新父页面
										parent.location.reload();
									});
					}else{
										window.top.layer.msg(res.msg, {icon: 2, time: 1000,shade:[0.5,'#000']});
										return;
					}
				}
			});
		});	
			
		
        function field_setting(type) {
            var data =  '';
            var url =  "{:url('fieldType')}?mid={:input('mid')}&type="+type.value;
            $.ajax({
                type: "POST",
                url: url,
                data: data,
                beforeSend:function(){
                    $('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
                    form.render()
                },
                success: function(msg){
                    $('#field_setup').html(msg);
                    form.render()
                },
                complete:function(){
                },
                error:function(){
                }
            });
        }
    });
</script>
</body>
</html>